/* 
 *   Date       Developer   Description
 *   
 *
 *   Classname:  zzz.test.component.mina2.test01.server.Test01ServerHandler
 * 
 *   Date:   2014-3-16
 * 
 *   The source code contained in this listing is proprietary to
 *   HLJ POST YITONG INFO-NET CO.,LTD.
 * 
 *   Unauthorized copying, adaptation, distribution, use, or display
 *   is strictly prohibited.
 *   This software is Copyright 2014 HLJ POST YITONG INFO-NET CO.,LTD.
 */
package com.titan.demo.camel.sample.component.mina2.test01.server;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.titan.demo.camel.sample.component.mina2.test01.common.dto.PhoneMessageDto;


/**
 *
 *
 * @author Administrator
 *
 */
public class Test01ServerHandler extends IoHandlerAdapter {
    public static Logger logger = LoggerFactory.getLogger(Test01ServerHandler.class);

    @Override
    public void messageReceived(IoSession session, Object message)
            throws Exception {
        PhoneMessageDto phoneMes = (PhoneMessageDto) message;
        String sendPhone = phoneMes.getSendPhone();
        String receivePhone = phoneMes.getReceivePhone();
        String mes = phoneMes.getMessage();
        logger.info("发送人手机号码：" + sendPhone);
        logger.info("接受人手机号码：" + receivePhone);
        logger.info("发送信息：" + mes);

        // 短信信息存入移动服务端数据库
        // ............

        session.write("发送成功！");
    }

    @Override
    public void messageSent(IoSession session, Object message) throws Exception {
        session.close(false);
    }
    @Override
    public void exceptionCaught(IoSession session, Throwable cause)
            throws Exception {
        logger.error("服务端发送异常...", cause);
    }
}

